package cn.steel.utils;

/**
 * @author: zhaoyuhan
 * @date: 2025/4/29
 * @description: 接口定义
 */

import cn.steel.domain.entity.User;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;
@Data
public class AuthUser implements UserDetails {
    private Long id;
    private String username;
    private String role; // 改为 String 类型
    private String company;
    private String password;

    public AuthUser(User user) {
        this.id = user.getId();
        this.username = user.getUsername();
        this.role = user.getRole(); // 直接赋值 String
        this.company = user.getCompany();
        this.password = user.getPassword();
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Collections.singleton(() -> "ROLE_" + role.toUpperCase());
    }

    @Override
    public String getPassword() {
        return password;
    }

    // Spring Security 使用这些判断账号状态
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }
    @Override
    public boolean isEnabled() {
        return true;
    }
}